{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5f976f46-9d51-407e-8eeb-e46cfdd22ae1",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "os.environ[\"OPENAI_API_KEY\"] = \"sk-your-key\"\n",
    "\n",
    "from llama_index.core.agent.workflow import FunctionAgent\n",
    "from llama_index.llms.openai import OpenAI"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "538e1519-2cfe-40f4-a861-65139156d2fe",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load the Plugin\n",
    "import requests\n",
    "import yaml\n",
    "\n",
    "f = requests.get(\n",
    "    \"https://raw.githubusercontent.com/sisbell/chatgpt-plugin-store/main/manifests/today-currency-converter.oiconma.repl.co.json\"\n",
    ").text\n",
    "manifest = yaml.safe_load(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b988f94e-6559-4404-9ba8-b41d4e4da770",
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index.tools.chatgpt_plugin.base import ChatGPTPluginToolSpec\n",
    "from llama_index.tools.requests.base import RequestsToolSpec\n",
    "\n",
    "requests_spec = RequestsToolSpec()\n",
    "plugin_spec = ChatGPTPluginToolSpec(manifest)\n",
    "# OR\n",
    "plugin_spec = ChatGPTPluginToolSpec(\n",
    "    manifest_url=\"https://raw.githubusercontent.com/sisbell/chatgpt-plugin-store/main/manifests/today-currency-converter.oiconma.repl.co.json\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "475cd741-e53e-4e9c-857b-6cb52641af0d",
   "metadata": {},
   "outputs": [],
   "source": [
    "agent = FunctionAgent(\n",
    "    tools=[*plugin_spec.to_tool_list(), *requests_spec.to_tool_list()], \n",
    "    llm=Openai(model=\"gpt-4.1\")\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "88175b8a-0345-44d2-8b78-983d7e7415bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(await agent.run(\"Can you give me info on the OpenAPI plugin that was loaded\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "39e42a58-a6db-47f0-8bd7-a4c3728f0839",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(await agent.run(\"Can you convert 100 euros to CAD\"))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
